home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / h / AToken.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  3.7 KB  |  110 lines  |  [TEXT/MPS ]

  1. /* ANTLRToken.h
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.31
  24.  * Terence Parr
  25.  * Parr Research Corporation
  26.  * with Purdue University and AHPCRC, University of Minnesota
  27.  * 1989-1995
  28.  */
  29.  
  30. #ifndef ATOKEN_H_GATE
  31. #define ATOKEN_H_GATE
  32.  
  33. #include <string.h>
  34.  
  35. #ifndef ANTLRCommonTokenTEXTSIZE
  36. #define ANTLRCommonTokenTEXTSIZE        100
  37. #endif
  38.  
  39. /* must define what a char looks like; can make this a class too */
  40. typedef char ANTLRChar;
  41.  
  42. class ANTLRAbstractToken {
  43. };
  44.  
  45. // If the user subclasses this one, then they must do their own syn()
  46. // routine and FAIL() routine.
  47. class ANTLRLightweightToken : public ANTLRAbstractToken {
  48. protected:
  49.         TokenType _type;
  50. public:
  51.         TokenType getType() { return _type; }
  52.         void setType(TokenType t) { _type = t; }
  53. };
  54.  
  55. // What does an ANTLR Token look like?
  56. // This has virtual functions so that minimum token
  57. // size >= sizeof('int') + sizeof(vtbl pointer).
  58. // If you want a totally light weight token and can make your own scanner
  59. // define ANTLRToken by itself without subclassing ANTLRTokenBase; or, you
  60. // can subclass the lightweight token above.
  61. class ANTLRTokenBase : public ANTLRLightweightToken {
  62. public:
  63.     /* Define to satisfy ANTLR error mechanism */
  64.     virtual int line() { return 0; }
  65.     virtual void setLine(int line) { ; }
  66.     virtual ANTLRChar *getText() { return (ANTLRChar *)""; }
  67.     virtual void setText(ANTLRChar *) {;}
  68.     virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line)
  69.         {
  70.             ANTLRTokenBase *t = new ANTLRTokenBase;
  71.             t->setType(tt); t->setText(txt); t->setLine(line);
  72.             return t;
  73.         }
  74. };
  75.  
  76. // if you are using DLG, your token def must derive from this class
  77. // min Token size is sizeof(TokenType) + space for virtual function table.
  78. class DLGBasedToken : public ANTLRTokenBase {
  79.     int _line;
  80. public:
  81.     int line() { return _line; }
  82.     void setLine(int line) { _line = line; }
  83.     DLGBasedToken(TokenType t) { setType(t); }
  84.     DLGBasedToken() {;}
  85.     virtual void setText(ANTLRChar *s) = 0;
  86.     virtual ANTLRChar *getText() = 0;
  87.     virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line) = 0;
  88. };
  89.  
  90. class ANTLRCommonToken : public DLGBasedToken {
  91. protected:
  92.     ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1];
  93. public:
  94.     ANTLRCommonToken(TokenType t, ANTLRChar *s) : DLGBasedToken(t)
  95.             { setText(s); }
  96.     ANTLRCommonToken() {;}
  97.     ANTLRChar *getText() { return _text; }
  98.     void setText(ANTLRChar *s) { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); }
  99.     virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line)
  100.         {
  101.             ANTLRCommonToken *t = new ANTLRCommonToken;
  102.             t->setType(tt); t->setText(txt); t->setLine(line);
  103.             return t;
  104.         }
  105. };
  106.  
  107. typedef ANTLRCommonToken ANTLRCommonBacktrackingToken;
  108.  
  109. #endif
  110.